package com.javayz.fileuploadanddownload.util;



import java.io.*;
import java.util.Arrays;

/**
 * @包名: ztgm_file
 * @类名: deleteFileUtils
 * @描述:
 * @作者: ZLQ
 * @创建时间: 2022年12月09日 11时:06分
 * @版本: 1.0
 **/
public class deleteFileUtils {

    public static  void  fileCloseDelete(FileInputStream inputStream , FileOutputStream outputStream, String dateUrl){
        //下载文件不存在进行文件夹删除
        try {
            if (inputStream != null){
                inputStream.close();
            }
            if (outputStream != null){
                outputStream.close();
            }
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }finally {
            //如果文件不存在会直接进行删除
            System.gc();
            //调用删除文件夹方法
            String deleteExc =  dateUrl.substring(dateUrl.lastIndexOf("/"));
            String[] split = dateUrl.split(deleteExc);
            String deleteUrl = Arrays.toString(split);

            deleteExc = deleteUrl.substring(deleteUrl.lastIndexOf("/"));
            split = deleteUrl.split(deleteExc);
            deleteUrl = Arrays.toString(split);

            deleteExc = deleteUrl.substring(deleteUrl.lastIndexOf("/"));
            split = deleteUrl.split(deleteExc);
            deleteUrl = Arrays.toString(split);

            deleteUrl = deleteUrl.replace("[", "");
            deleteUrl = deleteUrl.replace("]","");
            ZipUtils.deleteDir(new File(deleteUrl));
            //调用删除压缩包方法
            ZipUtils.deleteFile(deleteUrl+".zip");
        }
    }
}
